package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysCompanyReport;
import com.ruoyi.system.service.ISysCompanyReportService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 企业诊断报告Controller
 * 
 * @author ruoyi
 * @date 2023-06-26
 */
@Api(tags = "企业诊断报告")
@RestController
@RequestMapping("/system/report")
public class SysCompanyReportController extends BaseController
{
    @Autowired
    private ISysCompanyReportService sysCompanyReportService;

    /**
     * 查询企业诊断报告列表
     */
   // @PreAuthorize("@ss.hasPermi('system:report:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysCompanyReport sysCompanyReport)
    {
        startPage();
        List<SysCompanyReport> list = sysCompanyReportService.selectSysCompanyReportList(sysCompanyReport);
        return getDataTable(list);
    }

    /**
     * 导出企业诊断报告列表
     */
    @PreAuthorize("@ss.hasPermi('system:report:export')")
    @Log(title = "企业诊断报告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysCompanyReport sysCompanyReport)
    {
        List<SysCompanyReport> list = sysCompanyReportService.selectSysCompanyReportList(sysCompanyReport);
        ExcelUtil<SysCompanyReport> util = new ExcelUtil<SysCompanyReport>(SysCompanyReport.class);
        util.exportExcel(response, list, "企业诊断报告数据");
    }

    /**
     * 获取企业诊断报告详细信息
     */
    @ApiOperation(value = "获取企业诊断报告详细信息(根据企业id)")
  //  @PreAuthorize("@ss.hasPermi('system:report:query')")
    @GetMapping(value = "/{deptId}")
    public AjaxResult getInfo(@PathVariable("deptId") Long deptId)
    {
        return AjaxResult.success(sysCompanyReportService.selectSysCompanyReportByReportId(deptId));
    }

    /**
     * 新增企业诊断报告
     */
    @ApiOperation(value = "新增企业诊断报告")
  //  @PreAuthorize("@ss.hasPermi('system:report:add')")
    @Log(title = "企业诊断报告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysCompanyReport sysCompanyReport)
    {
        sysCompanyReport.setCreateBy(getUsername());
        return toAjax(sysCompanyReportService.insertSysCompanyReport(sysCompanyReport));
    }

    /**
     * 修改企业诊断报告
     */
    @ApiOperation(value = "修改企业诊断报告")
 //   @PreAuthorize("@ss.hasPermi('system:report:edit')")
    @Log(title = "企业诊断报告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysCompanyReport sysCompanyReport)
    {
        sysCompanyReport.setUpdateBy(getUsername());
        return toAjax(sysCompanyReportService.updateSysCompanyReport(sysCompanyReport));
    }

    /**
     * 删除企业诊断报告
     */
    @ApiOperation(value = "删除企业诊断报告")
 //   @PreAuthorize("@ss.hasPermi('system:report:remove')")
    @Log(title = "企业诊断报告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reportIds}")
    public AjaxResult remove(@PathVariable Long[] reportIds)
    {
        return toAjax(sysCompanyReportService.deleteSysCompanyReportByReportIds(reportIds));
    }
}
